

function receive(){
  $("#ro-table").empty();
    var url = "";
    var sid = document.getElementById("userid").innerText;
    var data = {
        seller: sid,
        status: '待买家寄回'
    }
    var gid = "";
    // var defer = $.Deferred();
$.ajax({
    url: "http://8.130.103.251:8080/returnForm/getSReturnForm",    //请求的url地址
    dataType: "json",   //返回格式为json
    ContentType: 'application/json;charset=utf-8', //传输格式
    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
    data: data,
    type: "GET",   //请求方式
  
   success: function(req) {
    //  console.log(req);
        var total = req.length;
        /*容器2参数*/
        var obj_2={
        obj_box:'#ro-table',//翻页容器
        total_item: total,//条目总数
        per_num:3,//每页条目数
        current_page:1//当前页
      };
      /*调用分页方法,初始化数据*/
      page_ctrl(obj_2);

        function page_ctrl(data_obj) {
        var obj_box=(data_obj.obj_box!== undefined)?data_obj.obj_box:function () {
          return;
        };//翻页容器dom对象,必要参数
      
        var total_item=(data_obj.total_item!== undefined)?parseInt(data_obj.total_item):0;//数据条目总数,默认为0,组件将不加载
        var per_num=(data_obj.per_num!== undefined)?parseInt(data_obj.per_num):3;//每页显示条数,默认为5条
        var current_page=(data_obj.current_page!== undefined)?parseInt(data_obj.current_page):1;//当前页,默认为1
        var total_page=Math.ceil(total_item/per_num);//计算总页数,不足2页,不加载组件

        //在指定容器内加载分页数据
        $(obj_box).append('<div class="page_content"></div>');
        //在指定容器内加载分页插件
        $(obj_box).append('<div class="page_ctrl"></div>');

        function page_even() {
          /*加载数据*/
            function change_content() {
              
            var p = total / 3 + 1;
          if(current_page <= p){
            var n =  current_page * 3 - 3
            var page_content=$('<tbody class="orderdata"></tbody>');

            while((n < total) && (n < current_page * 3))
            {
              var user = req[n];

              // 获得商品图片
              var oid = user.orderId;
              function getProData(){		
                var defer1 = $.Deferred();   //创建一个新的 Deferred（延迟）对象
                
                $.ajax({
                  url: "http://8.130.103.251:8080/order/getOrderById",    //请求的url地址
                  dataType: "json",   //返回格式为json
                  async: false, //请求是否异步，默认为异步，这也是ajax重要特性
                  data: {
                          orderId: oid //  "id": "value"
                  },    //参数值
                 type: "GET",   //请求方式
                
                 success: function(order) {
                  defer1.resolve(order);
                 }
              });
              return defer1.promise(); 
              }
              $.when(getProData()).done(function(order){
                $("#url020").val(order.productId);
                $("#url021").val(order.productName);
                $("#url022").val(order.status);
                $("#url023").val(order.rentalDay);
                $("#url024").val(order.rental);
                $("#url025").val(order.makeTime);
                $("#url026").val(order.exchangeHour);
                $("#url027").val(order.returnTime);
                $("#url028").val(order.shipStatus);
                }).fail(function(){
                alert("失败!");
              });

              var gid = $("#url020").val();

              function getData(){		
                var defer = $.Deferred();   //创建一个新的 Deferred（延迟）对象
                
                $.ajax({
                  url: "http://8.130.103.251:8080/good/getGood",    //请求的url地址
                  dataType: "json",   //返回格式为json
                  async: false, //请求是否异步，默认为异步，这也是ajax重要特性
                  data: {
                          goodid: gid//  "id": "value"
                  },    //参数值
                 type: "GET",   //请求方式
                
                 success: function(good) {
                  url = good.goodImg1;
                  defer.resolve(good);
                 }
              });
              return defer.promise(); 
              }
              $.when(getData()).done(function(good){
                //一般会强制将data转化为json对象
                $("#url02").val(good.goodImg1);
                }).fail(function(){
                alert("失败!");
              });

            var tr = $("<tr class='colist olist'></tr>");
            var td1 = "<td class='coid oid'>" + user.orderId + "</td>";
            var txt = "";
            if($("#url022").val() == 0)
            {
                txt = "租用";
            }
            else if($("#url022").val() == 1)
            {
              txt = "直接购买";
            }
            else if($("#url022").val() == 2)
            {
              txt = "以租代售";
            }
            // console.log($("#url01").val());
            var td2 = '<td class="coproduct oproduct">' + '<div class="copic">' + 
            '<img src=" '+ $("#url02").val() +' " alt="商品图片" class="coimg">' +
            '</div>' + '<div>' +  '<div class="coname">'+ $("#url021").val()
            + '</div>' + '<div class="cotype">' + txt + '</div>'
            + '</div>' + '</td>';
            var td3 =  '<td class="codate odate">' + $("#url023").val() + '</td>';
            var td4 =  '<td class="copay opay">' + $("#url024").val() + '</td>';
            var td50 = ' <td class="cotime otime">';
            var td51 = '';
            var td52 = '';
            var td53 = '';
            if($("#url025").val() != null)
            {
                td51 = '<div>创建时间:' + $("#url025").val() + '</div>';
            }
            if($("#url026").val() != null)
            {
                td52 = '<div>付款时间:' + $("#url026").val() + '</div>';
            }
            if($("#url027").val() != null)
            {
                td53 = '<div>归还时间:' +$("#url027").val() + '</div>';
            }
            var td54 = '</td>';
            var td5 = td50 + td51 + td52 + td53 + td54;
            var td6 = '<td class="costatus ostatus">' + $("#url028").val() + '</td>';
        
            
                var td7 = '<td class="cooperate ooperate">' + '</td>';

                tr.append(td1);
                tr.append(td2);
                tr.append(td3);
                tr.append(td4);
                tr.append(td5);
                tr.append(td6);
                tr.append(td7);
                page_content = page_content.append(tr);
                // console.log(n);

                n = n + 1;
                // ++index;
                
                
            }
            $(obj_box).children('.page_content').html(page_content);
          }
            
          }
      
          change_content();
          var inp_val=(current_page==total_page)?1:current_page+1;//跳转页数,input默认显示值
          var append_html='<button class="prev_page">上一页</button>';
          for(var i=0;i<total_page-1;i++){
            if(total_page>8&&current_page>6&&i<current_page-3){
              if(i<2){
                append_html+='<button class="page_num">'+(i+1)+'</button>';
              }
              else if(i==2){
                append_html+='<span class="page_dot">•••</span>';
              }
            }
      
            else if(total_page>8&&current_page<total_page-3&&i>current_page+1){
              if(current_page>6&&i==current_page+2){
                append_html+='<span class="page_dot">•••</span>';
              }else if(current_page<7){
                if(i<8){
                  append_html+='<button class="page_num">'+(i+1)+'</button>';
                }else if(i==8){
                  append_html+='<span class="page_dot">•••</span>';
                }
              }
              //append_html+='<span class="page_dot">•••</span>';
            }
      
            else{
              if(i==current_page-1){
                append_html+='<button class="page_num current_page">'+(i+1)+'</button>';
              }
      
              else{
                append_html+='<button class="page_num">'+(i+1)+'</button>';
              }
            }
          }
      
          if(current_page==total_page){
            append_html+='<button class="page_num current_page">'+(i+1)+'</button>';
          }else{
            append_html+='<button class="page_num">'+(i+1)+'</button>';
          }
      
          append_html+='<button class="next_page">下一页</button><span class="page_total">共 '+total_page+' 页, 到第</span><input class="input_page_num" type="text" value="'+inp_val+'"><span class="page_text">页</span><button class="to_page_num">确定</button>';
      
          $(obj_box).children('.page_ctrl').append(append_html);
          if(current_page==1){
            $(obj_box+' .page_ctrl .prev_page').attr('disabled','disabled').addClass('btn_dis');
          }else{
            $(obj_box+' .page_ctrl .prev_page').removeAttr('disabled').removeClass('btn_dis');
          }
      
          if(current_page==total_page){
            $(obj_box+' .page_ctrl .next_page').attr('disabled','disabled').addClass('btn_dis');
          }else{
            $(obj_box+' .page_ctrl .next_page').removeAttr('disabled').removeClass('btn_dis');
          }
        }
      
        page_even();
        $(obj_box+' .page_ctrl').on('click','button',function () {
          var that=$(this);
          if(that.hasClass('prev_page')){
            if(current_page!=1){
              current_page--;
              that.parent('.page_ctrl').html('');
              page_even();
            }
          }
      
          else if(that.hasClass('next_page')){
            if(current_page!=total_page){
              current_page++;
              that.parent('.page_ctrl').html('');
              page_even();
            }
          }
      
          else if(that.hasClass('page_num')&&!that.hasClass('current_page')){
            current_page=parseInt(that.html());
            that.parent('.page_ctrl').html('');
            page_even();
          }
      
          else if(that.hasClass('to_page_num')){
            current_page=parseInt(that.siblings('.input_page_num').val());
            that.parent('.page_ctrl').html('');
            page_even();
          }
        });
      
      }
      
    },

});
}